public class Search {
    public static void main(String[] args) {
        Search s= new Search();
        /*[4,5,6,7,0,1,2]
        0*/
        int[] nums = {5,1,3};

        int search = s.search(nums, 5);
        System.out.println(search);
    }
    public int search(int[] nums, int target) {
        // 采用二分法
        int left = 0;
        int right = nums.length-1;
        while(left<=right){
            int mid = (left+right)/2;
            if(target == nums[mid])return mid;
            if(nums[left]<=nums[mid] &&target>=nums[left] &&target<nums[mid]  ){
                right = mid-1;
            }else if(nums[left]<=nums[mid]){
                left = mid+1;
            }else if(nums[left]>nums[mid] && (target<nums[left] && target>nums[mid])){
                left = mid+1;
            }else{
                right = mid-1;
            }
        }
        return -1;
    }
}
